﻿using IdentityServer3.Core.Configuration;
using IdentityServer3.Core.Models;
using IdentityServer3.EntityFramework;
using Ptolemy.SSO.IdentityServer;
using System.Collections.Generic;
using System.Linq;

namespace Ptolemy.SSO
{
    public class Factory
    {
        public static IdentityServerServiceFactory Configure(string connString)
        {
            var efConfig = new EntityFrameworkServiceOptions
            {
                ConnectionString = connString,
            };

            var factory = new IdentityServerServiceFactory();

            factory.RegisterConfigurationServices(efConfig);
            factory.RegisterOperationalServices(efConfig);
            factory.ConfigureClientStoreCache();
            factory.ConfigureScopeStoreCache();

            // InMemoryTest
            factory.UseInMemoryUsers(Users.Get());

            return factory;
        }
    }
}